<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<%@page import="com.webside.points.wechat.Wechat"%>
<%
	
	String  openId = (String)request.getSession().getAttribute("openId");
	
 %>
<%-- <% 
 	String openId=(String)request.getSession().getAttribute("openId");
 %> --%>
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
  <meta name="keywords" content="" />
  <meta name="description" content="" />
  <link rel="stylesheet" href="../css/amazeui.min.css">
  <link rel="stylesheet" href="../css/wap.css">
  	<link rel="stylesheet" href="../css/style.css"/>
  	<link rel="stylesheet" href="../css/weui.css" />
		<script src="../js/jquery.min.js"></script>
	  <script type="text/javascript" src="../js/timeago.js"></script>
	   <script type="text/javascript"
	src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
  		<link rel="stylesheet" href="../css/dropload.css">
	<script src="../js/dropload.min.js"></script>
  <title>专家信息</title>
   <style type="text/css">
	.btn{
		width: 40%;
		display:inline-block;
		float:left;
		text-align: center;
		background:#22ac38;
		margin:0px 5% 25px 5%;
		color:#fffefe;
		border-radius:17px;
		padding:5px 0px;
	}
  </style>
  <script>
  
	function wxConfig(){
		
			var url = "${ctx }/wechat/getWxSignatureByTicket";
			
			var href=window.location.href;
			var params = {"url":href};
			   
			$.post(url, params, function(data, status, xhr){
				callbackConfig(data);
			},'json');
		}
		wxConfig();
		function callbackConfig(data) {
			 wx.config({
			      debug: false,
			      appId: data.appId,
			      timestamp: data.timestamp,
			      nonceStr: data.noncestr,
			      signature: data.signature,  
			      jsApiList: [
					'checkJsApi',
					'onMenuShareTimeline',
					'onMenuShareAppMessage',
					'hideMenuItems'
			      ]
			  }); 
		}
		
		//检查接口是否能调用
		wx.ready(function () {
			wx.checkJsApi({
			    jsApiList: [
			        'playVoice',
			        'playVoice'
			    ],
			    success: function (res) {
			        // alert(JSON.stringify(res));
			        // alert(JSON.stringify(res.checkResult.getLocation));
			        if (res.checkResult.getLocation == false) {
			            alert('你的微信版本太低，不支持微信JS接口，请升级到最新的微信版本！');
			            return;
			        }
			    }
			});
			var href=window.location.href;
			var name = $("#nameId").val();
			var title = name+" | "+$(".pet_grzx_map").text();
			var url = $("#url").attr("src");
			var answerCount = $("#answerCountId").val();
			var expertType = $("#expertTypeId").val();
			
			$.ajax({ 
			       type: "post", 
			       url: "${ctx}/issueType/findByIssueTypeId", 
			       async:false, 
			       data:"id="+expertType,
			       success: function(data){ 
					   var data = eval('(' + data + ')');
			    	   expertType = data.issueTypeName;
			       } 
				});
			
			var desc = "中穆问答"+expertType+"专家，目前已经解答"+answerCount+"个问题。【向他提问】";
			
			//alert(desc);
			
			//分享给朋友圈
			wx.onMenuShareTimeline({
				title: title, // 分享标题
				link: href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
				imgUrl: url, // 分享图标
				success: function () { 
					// 用户确认分享后执行的回调函数
				},
				cancel: function () { 
					// 用户取消分享后执行的回调函数
				}
			});
			//分享给朋友
			wx.onMenuShareAppMessage({
				title: title, // 分享标题
				desc: desc, // 分享描述
				link: href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
				imgUrl: url, // 分享图标
				success: function () { 
					// 用户确认分享后执行的回调函数
				},
				cancel: function () { 
					// 用户取消分享后执行的回调函数
				}
			});
		});
  
  
	function login(){
		window.location.href="../wechat/getWeChatCode";
	}
	$(function(){
		
		 //分享操作数据进行授权
			var openId = $("#openId").val();
			
			if(openId=='null&'){

				$("#isRewardId").attr("href","#");
				$("#isRewardId").attr("onclick","login()");
				
				$("#isIssueId").attr("href","#");
				$("#isIssueId").attr("onclick","login()");
			}
			
			
		
		
		
			//时间转换为简单的文字
			
			$(".timeago").each(function(){
				var id = $(this).attr("id");
				var time = timeago(id);
				$(this).text(time);
			})	
			
			$(function(){
			// 页数
			var page = 0;
			// 每页展示多少个
			var size = 10;
			var expertId = $("#expertId").val();
			var expert = $("#expert").val();
			var userId = $("#userId").val();
			//var user = ${user};
			//alert();
			// dropload
			$('.content').dropload({
				scrollArea : window,
				loadDownFn : function(me){
					page++;
					// 拼接HTML
					var result = '';
					$.ajax({
						type: 'post',
						url: '../expert/findExpertAnswer?page='+page+"&size="+size+"&expertId="+expertId,
						dataType: 'json',
						success: function(data){
							var arrLen = data.length;
							//alert(page);
							if(arrLen > 0){
								for(var i=0; i<arrLen; i++){
									//判断是否停用
									if(data[i].status==1){
										 var html =   '<li class="am-g am-list-item-desced pet_list_one_block">'
											+' <a href="${ctx }/issue/findById?issueId='+data[i].id+'">'
											+'<div class="pet_list_one_info">'
												+'<div class="pet_list_one_info_l">'
													+'<div class="pet_list_one_info_ico"><img src="../images/anonymity.jpg" alt=""></div>'
													+'<div class="pet_list_one_info_name">匿名用户</div>'
												+'</div>'
												+' <div class="pet_list_one_info_r">'
												+' <div class="pet_list_tag"><span class="timeago">'+timeago(data[i].createDateFormat)+'</span></div>'
												+'</div>'
											+'</div>'
											+'<div class=" am-list-main">'
												+'<h3 class="am-list-item-hd pet_list_one_bt" style="color: #222;font-weight: bold;">'+data[i].issueContent+'</h3>'
											+'</div>'
											+' <div style="color:#969595;font-size:1.1rem;margin-top:10px;" id="'+data[i].id+'" class="like">'
											+'<span id="like'+data[i].id+'">0点赞 </span>'
											+'<span id="dislike'+data[i].id+'">0倒赞</span>'
											+'<span>' +data[i].browseNumber+'浏览</span>'
											+'</div>'
											+'</a>'
										+'</li>'; 
										
										//alert(userId);

										if(data[i].anonymity=='on' && data[i].userEntity.id!=userId){
											if(expert==0){
												
											}else{
												html=html.replace("../images/anonymity.jpg",data[i].userEntity.headUrl)
												html=html.replace("匿名用户",data[i].userEntity.wechatId)
											}
										}else{
											html=html.replace("../images/anonymity.jpg",data[i].userEntity.headUrl)
											html=html.replace("匿名用户",data[i].userEntity.wechatId)
										}
										result = result+html;
									}
								}
													
							// 如果没有数据
							}else{
								// 锁定
								me.lock();
								// 无数据
								me.noData();
							}
							// 插入数据到页面，放到最后面
							$('.am-list').append(result);
							// 每次数据插入，必须重置
							me.resetload();
							
							$("li .like").each(function(){
								var id=$(this).attr("id");
								 //alert(id);
								var span=$(this);
								var url="${ctx}/answer/findByIssueId";
								$.post(url, {"issueId":id}, function(data, status, xhr){
									callback(data);
								},'json');
								function callback(data){
									var like=0;
									var dislike=0;
									for(var i=0;i<data.length;i++){
										like+=data[i].likeMark;
										dislike+=data[i].dislikeMark;
									}
									//alert($("#like"+id).length);
									$("#like"+id).text(like+"人点赞 ");
									$("#dislike"+id).text(dislike+"人倒赞 ");	
								}	
							 });
							
						},
						error: function(xhr, type){
							//alert('Ajax error!');
							// 即使加载出错，也得重置
							me.resetload();
						}
					});
				}
			});
		})
	})
  </script>
</head>
<body style="background:#ececec">
<input type="hidden" value="${expertEntity.id }" id="expertId">
<input type="hidden" value="<%=openId%>&" id="openId">
<input type="hidden" value="${user.expertId}" id="expert">
<input type="hidden" value="${user.id}" id="userId">
<input type="hidden" value="${answerCount}" id="answerCountId">
<input type="hidden" value="${expertEntity.expertType}" id="expertTypeId">
<input type="hidden" value="${expertEntity.name}" id="nameId">
  <div class="pet_mian" >
    <div class="pet_content pet_content_list">
      <div class="pet_grzx">
          <div class="pet_grzx_nr">
              <div class="pet_grzx_ico">
                  <img id="url" src="${expertEntity.userEntity.headUrl }" alt="">
              </div>
              <div class="pet_grzx_name">${expertEntity.userEntity.wechatId }</div>
             <div class="pet_grzx_map" style="font-size: 15px">${expertEntity.workUnit }${expertEntity.duty }</div> 
              <div class="pet_grzx_num_font" style="padding-top: 5px;">
				${expertEntity.describe}

              </div>
				
              <div class="pet_grzx_num">
                <span style="width: 25%;">
                	${answerCount}
                	<i>回答</i>
                </span>
                <span style="width: 25%;">
               		${expertEntity.likeCount}
               		 <i>喜欢</i>
                </span>
                <span style="width: 25%;">
					${expertEntity.dislikeCount}
                	<i>不喜欢</i>
                </span>
				 <span style="width: 25%;">
					${expertEntity.rewardAmount}
                	<i>打赏</i>
                </span>
				
				
              </div>
			 <div style="width:100%;font-size:15px;">
				<a href="${ctx }/service/character-issue.jsp?issueTypeId=${expertEntity.expertType }&pId=0&openId=<%=openId%>&expert=${expertEntity.id}&type=issue" id="isIssueId" class="btn"> <span >提 问</span></a>
				<a  href="${ctx }/service/reward.jsp?expertId=${expertEntity.id}" id="isRewardId" class="btn"><span >打 赏</span></a>
			<div>

          </div>

          </div>

        </div>

      </div>
	  <div class="pet_mian">
		<div class="pet_content pet_content_list">
		  <div class="pet_article_like" style="margin-top: 10px;">
			<div class="pet_content_main pet_article_like_delete">
			  <div data-am-widget="list_news" class="am-list-news am-list-news-default am-no-layout">
				<div class="am-list-news-bd content">
				  <ul class="am-list">
					  
				  </ul>
				  </div>

				</div>

			  </div>

			</div>

		  </div>
		</div>
 <!--底部-->
    <div data-am-widget="navbar" class="am-navbar am-cf my-nav-footer " id="">
     <ul class="am-navbar-nav am-cf am-avg-sm-4 my-footer-ul">
		<li>
           <a href="${ctx }/user/findUserIssue?issueTypeId=0" class="">
            <span class="am-icon-home"></span>
            <span class="am-navbar-label">首页</span>
          </a>
        </li>
        <li>
          <a href="${ctx }/issueType/findAll?mark=service&openId=<%=openId %>" class="">
            <span class="am-icon-comments"></span>
            <span class="am-navbar-label">提问</span>
          </a>
        </li>
		<li>
          <a href="${ctx }/postType/findAllPostType" class="">
            <span class="am-icon-book"></span>
            <span class="am-navbar-label">学习</span>
          </a>
        </li>
        <li style="position:relative">
          <a href="${ctx }/user/findByOpenId?openId=<%=openId %>" class="">
            <span class="am-icon-user"></span>
            <span class="am-navbar-label">我的</span>
          </a>
        </li>
      </ul>
</div>
    </div>
    </div>
    <script src="../js/amazeui.min.js"></script>
  <script src="../js/text-calculation.js"></script>
</body>
  </html>